package lol.clann.bukkit.pluginboot.model;

import org.bukkit.inventory.ItemStack;

import javax.annotation.Nonnull;

/**
 * 封装ItemStack
 * ItemStack的getQuatity方法不能返回负数
 * 此类用来包装他,支持负数,主要用于计数
 *
 * @author pyz
 * @date 2018/6/18 上午9:38
 */
public class ItemStackHolder implements Cloneable {

    private final ItemStack o;
    private int count;

    public ItemStackHolder(@Nonnull ItemStack itemStack, int count) {
        o = itemStack;
        this.count = count;
    }

    public int getQuantity() {
        return count;
    }

    public ItemStackHolder setQuantity(int count) {
        this.count = count;
        return this;
    }

    public ItemStackHolder plusQuantity(int count) {
        this.count += count;
        return this;
    }

    public ItemStackHolder minusQuantity(int count) {
        this.count -= count;
        return this;
    }

    public ItemStack getHandle() {
        return o;
    }

    @Override
    public ItemStackHolder clone() {
        return new ItemStackHolder(o.clone(), count);
    }
}
